package com.gimi.cloud.bbp.manage.service.page.impl;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.gimi.cloud.bbp.common.utils.MyBeanUtils;
import com.gimi.cloud.bbp.common.utils.StringUtil;
import com.gimi.cloud.bbp.dao.dao.page.PageModelPhotoDao;
import com.gimi.cloud.bbp.dto.page.PageModelPhotoDTO;
import com.gimi.cloud.bbp.entity.page.PageModelPhoto;
import com.gimi.cloud.bbp.manage.service.page.PageModelPhotoService;

@Service
public class PageModelPhotoServiceImpl implements PageModelPhotoService{
	
	@Autowired PageModelPhotoDao dao;
	
	@Override
	@Transactional
	public PageModelPhoto saveInfo(PageModelPhotoDTO dto) { 
		PageModelPhoto entity = null;
		if (dto.getId() != null) {
			entity = dao.queryBy("id", dto.getId());
		}
		if (entity != null) {
			MyBeanUtils.copyPropertiesIgnoreNullAndEmptyStr(dto, entity);
			dao.baseUpdateByPrimaryKey(entity);
		} else {
			entity = new PageModelPhoto();
			MyBeanUtils.copyPropertiesIgnoreNullAndEmptyStr(dto, entity);
			entity.setIsDelete(0);
			dao.insertUseGeneratedKeys(entity);
		}
		return entity;
	}
	
	@Override
	@Transactional
	public Long delByModelId(String modelId) {
		if (StringUtil.isEmpty(modelId)) {
			return 0L;
		}
		return dao.delByModelId(modelId);
	}

}
